package com.Socket.lianxi.homework;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class SocketTCPserver01 {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(9999);
        System.out.println("服务端，在端口9999，等待链接...");

        Socket socket = serverSocket.accept();
        InputStream inputStream = socket.getInputStream();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        String s = bufferedReader.readLine();
        System.out.println(s);
        while (s != "t"){
            String answer = "";
            if ("name".equals(s)){
                answer = "nova";
            }else if ("hobby".equals(s)){
                answer = "编写java程序";
            }else {
                answer = "你说的啥";
            }
            OutputStream outputStream = socket.getOutputStream();
            BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream));
            bufferedWriter.write(answer);
            bufferedWriter.newLine();
            bufferedWriter.flush();



        }
//        bufferedWriter.close();
//        outputStream.close();
        bufferedReader.close();
        inputStream.close();
        socket.close();
        serverSocket.close();

    }
}
